#!/usr/bin/env python
# coding:utf-8

import pymysql, sys

# reload(sys)
# sys.setdefaultencoding('utf8')

# sql=sys.argv[1]

def select_mysql(sql):
    conn = pymysql.connect(host='121.201.72.168', port=56033, user='daxmall_r', passwd='2hGUnCKoEuvkWNgRbvwo',
                           db='daxmall',
                           charset='UTF8')
    # conn = pymysql.connect(host='10.0.0.141', user='daxmall_r', passwd='2hGUnCKoEuvkWNgRbvwo', db='daxmall',
    #                        charset='UTF8')

    cur = conn.cursor()
    reCount = cur.execute(sql)

    nRet = cur.fetchall()
    cur.close()

    conn.close()
    return nRet


def insert_mysql(sql):
    conn = pymysql.connect(host='121.201.68.21', port=3307, user='jiang', passwd='jiangwenhui', db='daxiangzhanshi',

                           charset='UTF8')

    cur = conn.cursor()

    cur.execute(sql)
    nRet = cur.fetchall()
    conn.commit()

    cur.close()

    conn.close()
    return nRet

if __name__ == "__main__":
    #sql="SELECT SUM(s.total) AS 订单总金额  FROM ls_sub s  WHERE s.update_date >= curdate() AND s. STATUS > 1 AND s. STATUS !=5 "
    #sql="SELECT SUM(s.actual_total) as 订单总金额 FROM ls_sub s  WHERE s.pay_date >= curdate() and s.status > 1 AND s. STATUS != 5 "
   # sql="SELECT 	sum(t.cash_amount) as 订单总金额	FROM	ls_sub_settlement t	WHERE	t.clearing_time >= curdate()	AND t.is_clearing = 1	AND t.flow_trade_no IS NOT NULL; "
    sql="SELECT SUM(s.actual_total) as 订单总金额 FROM ls_sub s  WHERE s.sub_date >= curdate() "
    data =select_mysql(sql)[0][0]
    update_sql="update order_total set order_total=%s"%float(data)
    insert_mysql(update_sql)
    print(update_sql)
